<?php

	if(!defined('YMT')) exit;
	
	/**
	 * @package Yomm
	 * @author bsuter
	 *
	 */
	Class Yomm_Alias {
		
		/**
		 * table of available alias names
		 * @var $_alias_table [array] old name(alias name) => real name in the library
		 */
		private $_alias_table = array(
			"CmsModule" => "Yomm_Module_Cms",
			"Framework" => "Yomm_Controller",
			"ydsql" => "Yomm_Db_Query",
			"Tools" => "Yomm_Library_CmsTools",
			"devmod" => "Yomm_Devmod_Devmod",
			"Image" => "Yomm_Library_Image"
		);
		
		public function __construct($original_class)
		{
			if(!array_key_exists($original_class, $this->_alias_table))
			{
				throw new Yomm_Error("There is no Alias name available for Original class {$original_class}. Class not Found!");
				return null;
			}
			
			new $this->_alias_table[$original_class]();
			
			if(!class_alias($this->_alias_table[$original_class], $original_class))
			{
				throw new Yomm_Error("Error while generating the class alias for {$original_class}");
				return null;
			}	
		}
		
	}
	
	/* old php version fix for class_alias; dirty */
	if(!function_exists('class_alias'))
	{
    	function class_alias($original, $alias)
    	{
    		eval('abstract class ' . $alias . ' extends ' . $original . ' {}');
    		return true;
    	}
	}